<template>
  <div class="right">
    <h1>Username</h1>
    <input type="text" v-model.trim="username" />
    <h1>Password</h1>
    <input type="password" v-model.trim="password" />
    <div class="submit" @click="signIN">Sign In</div>
    <a href="#" @click="toRest">Forgot Password</a>
    <a href="#" @click="toRegister">Register</a>
  </div>
</template>

<script>
import { mapActions, mapState } from "vuex";
import md5 from "js-md5";
export default {
  name: "Login",
  data() {
    return {
      username: "",
      password: "",
    };
  },
  computed:{
    ...mapState('login',['token','message','user'])
  },
  methods: {
    toRegister() {
      this.$bus.$emit("changePosition", 1);
      this.$bus.$emit("changeTitle", 1);
      this.$bus.$emit("toleft", 1);
    },
    toRest() {
      this.$bus.$emit("changePosition", 1);
      this.$bus.$emit("changeTitle", 2);
      this.$bus.$emit("toleft", 0);
    },
    ...mapActions("login", ["login"]),
    signIN() {
      if (this.username.trim() === "") {
        alert("Please enter username");
        return;
      } else if (this.password.trim() === "") alert("Please enter password");
      else {
        this.login({
          username: this.username,
          password: this.password,
        });

        setTimeout(() => {
          if(this.token!=""){
            this.$router.push("home");
            // alert('登录成功')
          }else{
            if(this.message!=null){
              alert(this.message)
            }else{
              alert('网络请求超时')
            }
          }
        }, 1000);


        this.username=""
        this.password=""
      }
    },
  },
};
</script>

<style scoped>
.right {
  width: 50%;
  height: 100%;
  position: absolute;
  top: 0;
  right: 0;
  border-radius: 0 20px 20px 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: left;
  /* backdrop-filter: blur(100px); */
}
.right h1 {
  font-family: "Times New Roman", Times, serif;
  font-size: 2em;
  color: rgb(92, 183, 234);
  margin-left: 50px;
  margin-bottom: 10px;
  text-shadow: 0 0 5px rgb(92, 183, 234, 0.5);
}
.right input {
  font-family: "Times New Roman", Times, serif;
  position: relative;
  margin-left: 50px;
  margin-bottom: 10px;
  width: 250px;
  height: 35px;
  box-sizing: border-box;
  color: rgb(92, 183, 234);

  font-size: 1.5em;

  padding-left: 5px;
  outline: none;
  border-top: 0;
  border-right: 0;
  border-left: 0;
  border-bottom-color: rgba(92, 183, 234);
  border-bottom-width: 3px;

  transition: all 0.5s;

  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  border-radius: 10px;

  caret-color: rgba(92, 183, 234);
}
.right input:nth-of-type(2) {
  margin-bottom: 40px;
}
.right input:focus {
  transform: scale(1.05);
  border-color: rgba(92, 183, 234);

  outline: 0;
}

.submit {
  font-family: "Times New Roman", Times, serif;
  position: relative;
  box-sizing: border-box;
  margin-left: 50px;
  top: 10px;
  width: 250px;
  height: 50px;
  border-radius: 10px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  background-color: rgb(92, 183, 234);
  line-height: 50px;
  text-align: center;
  color: white;
  text-transform: uppercase;
  font-size: 2em;
  text-shadow: 0 0 10px rgb(0, 0, 0, 0.5);
  transition: all 0.5s;
  cursor: pointer;
  margin-bottom: 50px;
}

.submit:hover {
  transform: scale(1.05);
}
.right a:nth-of-type(1) {
  position: absolute;
  left: 55px;
  bottom: 40px;
  font-family: "Times New Roman", Times, serif;
  font-size: 1em;
  color: rgb(92, 183, 234);
  text-align: left;
}

.right a:nth-of-type(2) {
  position: absolute;
  right: 55px;
  bottom: 40px;
  font-family: "Times New Roman", Times, serif;
  font-size: 1em;
  color: rgb(92, 183, 234);
  text-align: left;
}
</style>